package edu.udo.sopra10.chaturaji.entities;

import static java.util.Collections.unmodifiableList;

import java.util.ArrayList;
import java.util.List;

import edu.udo.sopra10.chaturaji.entities.coordinates.Position;

/**
 * Abstract game class.
 * 
 * @author Patrick Westerhoff
 */
public class AbstractGame
{
	/**
	 * The game board, consisting of 64 {@link Square}s.
	 */
	protected final Square[][] board = new Square[ 8 ][ 8 ];
	/**
	 * All {@link Player}s participating in the game, in order of their turns.
	 */
	protected final List<Player> players = new ArrayList<Player>(4);
	
	public AbstractGame ()
	{
		super();
	}
	
	/**
	 * Get the current game board. This method does not make any attempt to
	 * preserve referential integrity, and all writes to the returned array will
	 * write through to the game board. Use the return value with care.
	 * 
	 * @return the game board, not copied, never {@code null}, never contains
	 *         {@code null}.
	 */
	public Square[][] getBoard ()
	{
		return board;
	}

	/**
	 * Get a {@link Square} on the game board.
	 * 
	 * @param position
	 *            the square's position on the board, must not be {@code null}.
	 * @return the associated square, never {@code null}.
	 */
	public Square getSquare ( final Position position )
	{
		if (position == null) {
			throw new NullPointerException("position must be non-null");
		}
		return board[position.getX()][position.getY()];
	}

	/**
	 * Get all {@link Player}s participating in the game.
	 * 
	 * @return all players participating, in order of their turns, never
	 *         {@code null}, never contains {@code null}, always unmodifiable.
	 */
	public List<Player> getPlayers ()
	{
		return unmodifiableList(players);
	}
}